package com.fmsh.nfcsensor.utils;

import android.nfc.tech.NfcA;
import android.os.SystemClock;

import com.fmsh.base.utils.FMUtil;
import com.fmsh.base.utils.LogUtil;
import com.fmsh.nfcsensor.bean.GasIndexAlgorithmParams;

import java.io.IOException;

/**
 * @author wuyajiang
 * @date 2022/11/18
 */
public class Test {

    public static void main(String[] args){
        try {
            initGas();
            for (int i = 0; i < 70; i++) {
                System.out.println(i);

                parseGas();
            }

        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    public static int voc_index_value;
    public static int nox_index_value;
    public static short[] sraw_voc= new short[48];
    public static short[] sraw_nox= new short[48];
    public static GasIndexAlgorithmParams voc_params = new GasIndexAlgorithmParams();
    public static GasIndexAlgorithmParams nox_params = new GasIndexAlgorithmParams();
    private static void initGas() throws IOException {
        byte[] EEPROM_DATA = new byte[16];
        SensorUtils.GasIndexAlgorithm_init(voc_params, Constants.GasIndexAlgorithm_ALGORITHM_TYPE_VOC);
//        SensorUtils.GasIndexAlgorithm_init(nox_params, Constants.GasIndexAlgorithm_ALGORITHM_TYPE_NOX);

        GasUtils.GasIndexAlgorithm_init(voc_params,Constants.GasIndexAlgorithm_ALGORITHM_TYPE_VOC);

        String[] comand ={"70D570F170F070E670D870EB70E670D1","3FA93FB13FB03FA33FA13F9F3F9D3F99",
                "70F770DE70E570E470EC70E370F570E6","3F963F8F3F963F963F903F8B3F883F8D",
                "70D870E170D270D570F670E4710570D4","3F893F833F843F7F3F823F793F743F7A",
                "70D570E6712170FE70F170DE70DA70F3","3F733F703F6B3F6F3F693F6A3F613F69",
                "70D570E6712170FE70F170DE70DA70F3","3F733F703F6B3F6F3F693F6A3F613F69",
                "70D570E6712170FE70F170DE70DA70F3","3F733F703F6B3F6F3F693F6A3F613F69",
        };
        for (int j = 0; j < 6; j++)                    //Voc[15:8]为Block中Byte0，Voc[7:0]为Block中Byte1
        {
            //非接读EEPROM VOC数据：即j=0:'3010',j=1:'3018',j=2:'3020',j=3:'3028'  每条命令16Bytes数据；

//            EEPROM_DATA = FMUtil.hexToByte(comand[j*2]);
//            for (int i = 0; i < 8; i++) {
//
//                int a =  SensorUtils.getUint8(EEPROM_DATA[i * 2]) << 8;
//                int b =  SensorUtils.getUint8(EEPROM_DATA[i * 2 + 1]);
//                int c = a  + b;
//                sraw_voc[i + j * 8] = (short) c;
//            }
//
//            //非接读EEPROM：NOX数据,即'3014','301C','3024','302C'
//
//
//            EEPROM_DATA = FMUtil.hexToByte(comand[j*2+1]);
//            for (int i = 0; i < 8; i++) {
//                int a =  SensorUtils.getUint8(EEPROM_DATA[i * 2]) << 8;
//                int b =  SensorUtils.getUint8(EEPROM_DATA[i * 2 + 1]);
//                int c = a  + b;
//                sraw_nox[i + j * 8] = (short) c;
//            }
        }
//        for (int i = 0; i < 48; i++) {
//            System.out.println(sraw_voc[i]);
//            System.out.println(sraw_nox[i]);
//            voc_index_value=SensorUtils.GasIndexAlgorithm_process( voc_params, sraw_voc[i]);
//            nox_index_value= SensorUtils.GasIndexAlgorithm_process( nox_params, sraw_nox[i]);
//        }
        System.out.println("initVOC---"+voc_index_value);
        System.out.println("initnox---"+nox_index_value);
    }

    public static int count = 0;
    public static void parseGas() throws IOException {

        byte[] bytes= FMUtil.hexToByte(test()[count].replace(" ",""));
        count++;

        byte[] FIFO_DATA = new byte[bytes.length-1];
        System.arraycopy(bytes,1,FIFO_DATA,0,FIFO_DATA.length);
        sraw_voc[0]= SensorUtils.getUint8(FIFO_DATA[0]);
        sraw_voc[0]<<=8;
        sraw_voc[0]|=SensorUtils.getUint8(FIFO_DATA[1]);
        sraw_nox[0]= SensorUtils.getUint8(FIFO_DATA[3]);
        sraw_nox[0]<<=8;
        sraw_nox[0]|=SensorUtils.getUint8(FIFO_DATA[4]);
        System.out.println("sraw_voc  057379E73CDCFE"+sraw_voc[0]);
        System.out.println("sraw_nox"+sraw_nox[0]);

        voc_index_value=SensorUtils.GasIndexAlgorithm_process(voc_params, sraw_voc[0]);
//        nox_index_value=SensorUtils.GasIndexAlgorithm_process(nox_params, sraw_nox[0]);
        System.out.println("voc---"+voc_index_value);
        System.out.println("nox---"+nox_index_value);
    }

    public static String[] test(){
        String[] arr =
                {"0572527F3CE177"
                        ,"057258A43CDE9C"
                        ," 05722EFA3CDB69"
                        ," 057260D83CE046"
                        ," 05727A403CE482"
                        ," 057289913CDA58"
                        ," 05728F373CE224"
                        ," 0572A8263CE177"
                        ," 057298E33CDA58"
                        ," 057293093CDDCF"
                        ," 0572770C3CD83A"
                        ," 057298E33CDDCF"
                        ," 05729BB03CDFAD"
                        ," 0572745F3CE315"
                        ," 0572709B3CDFAD"
                        ," 05724D123CDB69"
                        ," 057258A43CD625"
                        ," 05729C273CDDCF"
                        ," 057295AF3CDDCF"
                        ," 0572745F3CD83A"
                        ," 05728C643CD3D0"
                        ," 0572A56A3CDDCF"
                        ," 0572763D3CD83A"
                        ," 05729E453CD90B"
                        ," 057299D23CD83A"
                        ," 057296FC3CD083"
                        ," 0572B1ED3CDE9C"
                        ," 0572C0243CD576"
                        ," 0572B1ED3CD714"
                        ," 057293093CD83A"
                        ," 0572C9AC3CD3D0"
                        ," 0572C6823CD3D0"
                        ," 0572B4183CE177"
                        ," 0572BB363CD3D0"
                        ," 0572E3F13CD90B"
                        ," 0572F0E13CDCFE"
                        ," 0572E2C03CD1B2"
                        ," 0572F2833CD625"
                        ," 057302F53CD90B"
                        ," 057312B63CDCFE"
                        ," 057312B63CDA58"
                        ," 057328A83CD83A"
                        ," 0573577E3CD576"
                        ," 0573611D3CD90B"
                        ," 05737B853CD83A"
                        ," 057379E73CDCFE"
                        ," 05736E333CD576"
                        ," 05735EF63CD447"
                        ," 0573828F3CD83A"
                        ," 05739EB13CD90B"
                        ," 05737C123CD714"
                        ," 057367BB3CD576"
                        ," 057333013CDB69"
                        ," 05730DDB3CD83A"
                        ," 0572EB483CCFEE"
                        ," 0572D7F03CD625"
                        ," 0572DD2B3CD1B2"
                        ," 0572D8DE3CD2E1"

                        ," 0572E92A3CDA58"

                        ," 057316723CD1B2"

                        ," 0573186D3CCEDF"
                        ," 05734DE63CDE9C"
                        ," 057376C93CD90B"
                        ," 05738FC33CD83A"
                        ," 057388543CD576"
                        ," 0573864B3CD625"
                        ," 057383BE3CD625"
                        ," 05736AF73CDDCF"
                        ," 05736E333CDCFE"
                        ," 0573624E3CD83A"};
        return arr;

    }


}
